
import { GlobalVar } from "../../common/globalvar";
import lgxcom from '../../common/common'
import layer from "../../layer/layer";

class layerInfo
{
    constructor(name){
        this.name = name;
        this.order = 1;
        this.display = true;
        this.lock = false;
        this.color = "#ffffff";
        this.linewidth = 1;
        this.linemode = 'solid';
    }
    
}
class LayerSvc {
    constructor(dataManger) {
        this.dataManger = dataManger;
    }

    getAllLayerData(){
        let layerMng = this.dataManger.getLayerManager();
        let list = layerMng.getAllLayer();
        let retList = [];
        let index = 1;
        list.forEach(t => {
            let info = new layerInfo(t.name);
            info.display = t.getVisible();
            info.order = index++;
            info.lock = t.getLock();
            info.color = t.getLineColor();
            info.linewidth = t.getLineWidth();
            info.linemode = t.getLineMode();
            retList.push(info);
        });
        let curentName = layerMng.getCurentLayer().getName();
        let ret = {list:retList,curentName};
        return ret;
    }

    newLayer(layerInfo){
        let ret = 0;
        let layerMng = this.dataManger.getLayerManager();
        let preLayer = layerMng.findLayer(layerInfo.name);
        if (!preLayer){
            let t = new layer.Layer(layerInfo.name);
            t.layerID = layerMng.getLayerMaxIndex()+1;
            layerMng.addLayer(t);
            t.setVisible(layerInfo.display);
            t.setLock(layerInfo.lock);
            ret = 1;
        }
        else{
            ret = -1;
        }
        return ret;
    }
    
    setCurent(name){
        this.dataManger.switchLayer(name);
    }
    
    delLayer(name){
    
    }
    
    setAllDisplay(disflag){
    
    }
    
    selAllGraphInLayer(name){
    
    }
    
    setLayerOrder(name,kind){
    
    }

    setLayerShow(name,visible){
        let layerMng = this.dataManger.getLayerManager();
        let destLayer = layerMng.findLayer(name);
        if (destLayer){
            destLayer.setVisible(visible);
        }
    }

    lockLayer(name,lock){
        let layerMng = this.dataManger.getLayerManager();
        let destLayer = layerMng.findLayer(name);
        if (destLayer){
            destLayer.setLock(lock);
        }
    }

}

export default { LayerSvc }